package dao

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"time"
)

// Site 场地表
type Site struct {
	Id           int64     `json:"id" gorm:"column:id;comment:自增id"`
	Name         string    `json:"name" gorm:"column:name;comment:场地名称"`
	Address      string    `json:"address" gorm:"column:address;comment:场地地址"`
	Longitude    float64   `json:"longitude" gorm:"column:longitude;comment:经度"`
	Latitude     float64   `json:"latitude" gorm:"column:latitude;comment:纬度"`
	Image        string    `json:"image" gorm:"column:image;comment:图片"`
	MaxPeopleNum string    `json:"max_people_num" gorm:"column:max_people_num;comment:最大容纳人数"`
	Facilities   []byte    `json:"facilities" gorm:"column:facilities;comment:设施情况"`
	Service      []byte    `json:"service" gorm:"column:service;comment:服务"`
	Options      []byte    `json:"options" gorm:"column:options;comment:选项"`
	Business     string    `json:"business" gorm:"column:business;comment:营业时间"`
	Phone        string    `json:"phone" gorm:"column:phone;comment:手机号"`
	Des          string    `json:"des" gorm:"column:des;comment:服务描述"`
	Mark         string    `json:"mark" gorm:"column:mark;comment:预约须知文字"`
	Sort         int       `json:"sort" gorm:"column:sort;comment:排序"`
	Status       uint8     `json:"status" gorm:"column:status;comment:状态"`
	IsDelete     uint8     `json:"is_delete" gorm:"column:is_delete;comment:1已删除"`
	UpdatedAt    time.Time `json:"update_at" gorm:"column:update_at;comment:更新时间"`
	CreatedAt    time.Time `json:"create_at" gorm:"column:create_at;comment:创建时间"`
}

func (f *Site) TableName() string {
	return "site"
}

// InitData 初始化site表
func (f *Site) InitData(tx *gorm.DB) error {
	return tx.AutoMigrate(f)
}

// Save 保存
func (f *Site) Save(c *gin.Context, tx *gorm.DB) error {
	if err := tx.WithContext(c).Save(f).Error; err != nil {
		return err
	}
	return nil
}
